home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / bbsutil / hsrc_117.zip / IBMPC.C < prev    next >
C/C++ Source or Header  |  1990-11-07  |  3KB  |  183 lines

  1.  
  2. /* Low-level functions addressing BIOS & PC Hardware */
  3.  
  4. #include "dos.h"
  5. #include "keys.h"
  6. #pragma inline
  7. static union REGS rg;
  8. #ifdef USECLOCK
  9.     extern void pascal print_clock(void);
  10. #endif
  11. extern cdecl printf(char *,...);
  12.  
  13. /* Position cursor */
  14.  
  15. void pascal cursor (int x, int y) {
  16.  
  17.   rg.x.ax=0x0200;
  18.   rg.x.bx=0;
  19.   rg.x.dx=((y<<8)&0xff00)+x;
  20.   int86 (16,&rg,&rg);
  21. }
  22.  
  23. /* Return cursor position */
  24.  
  25. void pascal curr_cursor (int *x,int *y) {
  26.  
  27.   rg.x.ax=0x0300;
  28.   rg.x.bx=0;
  29.   int86(16,&rg,&rg);
  30.   *x=rg.h.dl;
  31.   *y=rg.h.dh;
  32. }
  33.  
  34. /* Set cursor type */
  35.  
  36. void pascal set_cursor_type(int t) {
  37.  
  38.   rg.x.ax=0x0100;
  39.   rg.x.bx=0;
  40.   rg.x.cx=t;
  41.   int86(16,&rg,&rg);
  42. }
  43.  
  44. char attrib = 7;
  45.  
  46. /* Clear screen */
  47.  
  48. void pascal clear_screen() {
  49.  
  50.   cursor (0,0);
  51.   rg.h.al=' ';
  52.   rg.h.ah=9;
  53.   rg.x.bx=attrib;
  54.   rg.x.cx=2000;
  55.   int86(16,&rg,&rg);
  56. }
  57.  
  58. /* Return video mode */
  59.  
  60. int pascal vmode() {
  61.  
  62.   rg.h.ah=15;
  63.   int86(16,&rg,&rg);
  64.   return rg.h.al;
  65. }
  66.  
  67. /* Test for scroll lock */
  68.  
  69. int pascal scroll_lock() {
  70.  
  71.   rg.x.ax=0x0200;
  72.   int86(0x16,&rg,&rg);
  73.   return rg.h.al & 0x10;
  74. }
  75.  
  76. void (*helpfunc)();
  77. int helpkey=0;
  78. int helping=0;
  79.  
  80. /*Get a keyboard character */
  81.  
  82. int pascal get_char () {
  83.  
  84.   int c;
  85.  
  86.   while(1) {
  87.     rg.h.ah=1;
  88.     int86(0x16,&rg,&rg);
  89.     if (rg.x.flags & 0x40) {
  90. #ifdef USECLOCK
  91.       print_clock();
  92. #endif
  93.       continue;
  94.     }
  95.     rg.h.ah=0;
  96.     int86(0x16,&rg,&rg);
  97.     if (rg.h.al == 0) c=rg.h.ah | 128;
  98.     else c=rg.h.al;
  99.     if (c==helpkey && helpfunc) {
  100.        if (!helping) {
  101.          helping=1;
  102.          (*helpfunc)();
  103.          helping=0;
  104.          continue;
  105.        }
  106.      }
  107.      break;
  108.    }
  109.    return c;
  110. }
  111.  
  112.  
  113. void pascal vpoke (unsigned vseg, unsigned adr, unsigned chr) {
  114.  
  115.     if (vseg == 45056)
  116.         poke(vseg,adr,chr);
  117.     else {
  118.         _DI=adr;
  119.         _ES=vseg;
  120.         asm cld;
  121.         _BX=chr;
  122.         _DX=986;
  123.  
  124.         do
  125.             asm in al,dx;
  126.         while (_AL & 1);
  127.  
  128.         do
  129.             asm in al,dx;
  130.         while (!(_AL & 1));
  131.         _AL = _BL;
  132.         asm stosb;
  133.  
  134.         do
  135.             asm in al,dx;
  136.         while (_AL & 1);
  137.  
  138.         do
  139.             asm in al,dx;
  140.         while(!(_AL & 1));
  141.         _AL = _BH;
  142.         asm stosb;
  143.     }
  144. }
  145.  
  146. int pascal vpeek(unsigned vseg, unsigned adr) {
  147.  
  148.     int ch,at;
  149.  
  150.     if (vseg == 45056)
  151.         return peek(vseg,adr);
  152.     asm push ds;
  153.     _DX=986;
  154.     _DS=vseg;
  155.     _SI=adr;
  156.     asm cld;
  157.  
  158.     do
  159.         asm in al,dx;
  160.     while(_AL & 1);
  161.  
  162.     do
  163.         asm in al,dx;
  164.     while(!(_AL & 1));
  165.     asm lodsb;
  166.     _BL = _AL;
  167.  
  168.     do
  169.         asm in al,dx;
  170.     while(_AL & 1);
  171.  
  172.     do
  173.         asm in al,dx;
  174.     while(!(_AL & 1));
  175.     asm lodsb;
  176.     _BH=_AL;
  177.     _AX=_BX;
  178.     asm pop ds;
  179.     return _AX;
  180. }
  181.  
  182. /* End of IBMPC.C File */
  183.